package com.my.buffers;

import java.io.*;

/**
 * @description:
 * @author: marshal
 * @date: 2021-08-24 4:02 PM
 */
public class BufferedReaderTest {
    public static void main(String[] args) {
        String path = "file/br.txt";
        testReadLine(path);
    }

    /**
     *  read line
     *
     * @param path
     */
    private static void testReadLine(String path) {
        try (
                var fr = new FileReader(path);
                var br = new BufferedReader(fr);
        ) {
            String s = "";
            while ((s = br.readLine()) != null) {
                System.out.println(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * Reads characters into an array
     *
     * @param path
     */
    private static void testRead(String path) {
        try (
                var fr = new FileReader(path);
                var br = new BufferedReader(fr);
        ) {
            char[] buff = new char[1024];
            // he number of characters read
            var hasRead = 0;
            while ((hasRead = br.read(buff)) != -1) {
                System.out.println(hasRead);
                System.out.println(new String(buff, 0, hasRead));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
